package com.tuozixuan.javafx.control.alert;


import java.util.Optional;

import javafx.application.Application;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.stage.Stage;

/**
 * https://blog.csdn.net/liubanxian_/article/details/107075679
 */
public class AlertDemo extends Application {
	
    public static void main(String[] args) {
        launch(args);
    }

	@Override
	public void start(Stage primaryStage) throws Exception {
		
		Alert alert = new Alert(AlertType.INFORMATION);
        alert.setTitle("提示");
        alert.setHeaderText("元旦放假");
        alert.setContentText("元旦放假三天哦");
        alert.showAndWait();
        
        // 只有內容沒有頭信息的对话框
        alert = new Alert(AlertType.INFORMATION);
        alert.setTitle("提示");
        alert.setHeaderText(null);
        alert.setContentText("元旦放假三天哦");
        alert.showAndWait();
        
        alert = new Alert(AlertType.WARNING);
        alert.setTitle("警告");
        alert.setHeaderText("元旦放假");
        alert.setContentText("元旦放假三天哦");
        alert.showAndWait();
        
        alert = new Alert(AlertType.WARNING);
        alert.setTitle("警告");
        alert.setHeaderText(null);
        alert.setContentText("元旦放假三天哦");
        alert.showAndWait();
        
        alert = new Alert(AlertType.ERROR);
        alert.setTitle("错误");
        alert.setHeaderText("元旦放假");
        alert.setContentText("元旦放假三天哦");
        alert.showAndWait();
        
        alert = new Alert(AlertType.ERROR);
        alert.setTitle("错误");
        alert.setHeaderText(null);
        alert.setContentText("元旦放假三天哦");
        alert.showAndWait();
        
        
        alert = new Alert(AlertType.CONFIRMATION);
        alert.setTitle("错误");
        alert.setHeaderText("元旦放假");
        alert.setContentText("元旦放假三天哦");
        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == ButtonType.OK) {
        	System.out.println("ok");
        } else if (result.get() == ButtonType.CANCEL) {
        	System.out.println("cancel");
        } else {
        	System.out.println("other");
        }
        
	}

}
